package com.irdstudio.bsp.console.service.impl;

import java.util.List;
import java.util.Objects;

import com.irdstudio.bsp.console.dao.PluginAssignConfDao;
import com.irdstudio.bsp.console.dao.domain.PluginAssignConf;
import com.irdstudio.bsp.console.service.facade.PluginAssignConfService;
import com.irdstudio.bsp.console.service.vo.PluginAssignConfVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.sdk.beans.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 分单插件配置				<p>
 * @author srvadmin
 * @date 2020-07-24
 */
@Service("pluginAssignConfServiceImpl")
public class PluginAssignConfServiceImpl implements PluginAssignConfService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PluginAssignConfServiceImpl.class);

	@Autowired
	private PluginAssignConfDao pluginAssignConfDao;
	
	/**
	 * 新增操作
	 */
	public int insertPluginAssignConf(PluginAssignConfVO inPluginAssignConfVo) {
		logger.debug("当前新增数据为:"+ inPluginAssignConfVo.toString());
		int num = 0;
		try {
			PluginAssignConf pluginAssignConf = new PluginAssignConf();
			beanCopy(inPluginAssignConfVo, pluginAssignConf);
			num = pluginAssignConfDao.insertPluginAssignConf(pluginAssignConf);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PluginAssignConfVO inPluginAssignConfVo) {
		logger.debug("当前删除数据条件为:"+ inPluginAssignConfVo);
		int num = 0;
		try {
			PluginAssignConf pluginAssignConf = new PluginAssignConf();
			beanCopy(inPluginAssignConfVo, pluginAssignConf);
			num = pluginAssignConfDao.deleteByPk(pluginAssignConf);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginAssignConfVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PluginAssignConfVO inPluginAssignConfVo) {
		logger.debug("当前修改数据为:"+ inPluginAssignConfVo.toString());
		int num = 0;
		try {
			PluginAssignConf pluginAssignConf = new PluginAssignConf();
			beanCopy(inPluginAssignConfVo, pluginAssignConf);
			num = pluginAssignConfDao.updateByPk(pluginAssignConf);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginAssignConfVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PluginAssignConfVO queryByPk(PluginAssignConfVO inPluginAssignConfVo) {
		
		logger.debug("当前查询参数信息为:"+ inPluginAssignConfVo);
		try {
			PluginAssignConf queryPluginAssignConf = new PluginAssignConf();
			beanCopy(inPluginAssignConfVo, queryPluginAssignConf);
			PluginAssignConf queryRslPluginAssignConf = pluginAssignConfDao.queryByPk(queryPluginAssignConf);
			if (Objects.nonNull(queryRslPluginAssignConf)) {
				PluginAssignConfVO outPluginAssignConfVo = beanCopy(queryRslPluginAssignConf, new PluginAssignConfVO());
				logger.debug("当前查询结果为:"+ outPluginAssignConfVo.toString());
				return outPluginAssignConfVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginAssignConfVO> queryAllOwner(PluginAssignConfVO pluginAssignConfVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PluginAssignConfVO> list = null;
		try {
			List<PluginAssignConf> pluginAssignConfs = pluginAssignConfDao.queryAllOwnerByPage(pluginAssignConfVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pluginAssignConfs.size());
			pageSet(pluginAssignConfs, pluginAssignConfVo);
			list = (List<PluginAssignConfVO>) beansCopy(pluginAssignConfs, PluginAssignConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginAssignConfVO> queryAllCurrOrg(PluginAssignConfVO pluginAssignConfVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PluginAssignConf> pluginAssignConfs = pluginAssignConfDao.queryAllCurrOrgByPage(pluginAssignConfVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pluginAssignConfs.size());
		List<PluginAssignConfVO> list = null;
		try {
			pageSet(pluginAssignConfs, pluginAssignConfVo);
			list = (List<PluginAssignConfVO>) beansCopy(pluginAssignConfs, PluginAssignConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginAssignConfVO> queryAllCurrDownOrg(PluginAssignConfVO pluginAssignConfVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PluginAssignConf> pluginAssignConfs = pluginAssignConfDao.queryAllCurrDownOrgByPage(pluginAssignConfVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pluginAssignConfs.size());
		List<PluginAssignConfVO> list = null;
		try {
			pageSet(pluginAssignConfs, pluginAssignConfVo);
			list = (List<PluginAssignConfVO>) beansCopy(pluginAssignConfs, PluginAssignConfVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
